package net.sync.lesson3.sync001;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.PriorityBlockingQueue;

public class UsePriorityBlockingQueue {


    public static void main(String[] args) throws Exception {


        PriorityBlockingQueue<Task> q = new PriorityBlockingQueue<Task>();

        Task t1 = new Task();
        t1.setId(3);
        t1.setName("id为3");
        Task t2 = new Task();
        t2.setId(2);
        t2.setName("id为2");
        Task t3 = new Task();
        t3.setId(1);
        t3.setName("id为1");
        Task t0 = new Task();
        t0.setId(0);
        t0.setName("id为0");
        Task t5 = new Task();
        t5.setId(5);
        t5.setName("id为5");
        Task t4 = new Task();
        t4.setId(4);
        t4.setName("id为4");

        //return this.id > task.id ? 1 : 0;
        q.add(t1);    //3
        q.add(t3);  //1
        q.add(t2);    //4
        q.add(t0);  //0
        q.add(t5);  //5
        q.add(t4);  //5

        // 1 3 4
        System.out.println("容器：" + q);
        System.out.println(q.take().getId());
        System.out.println("容器：" + q);
		System.out.println(q.take().getId());
        System.out.println("容器：" + q);
		System.out.println(q.take().getId());
        System.out.println("容器：" + q);


    }
}
